package com.gimi.cloud.bbp.client.controller.userInfo;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gimi.cloud.bbp.client.service.userInfo.RdExpressInfoService;
import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.exception.MsgException;
import com.gimi.cloud.bbp.common.utils.JsonUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.common.utils.reqhead.Util;
import com.gimi.cloud.bbp.dto.userInfo.RdExpressInfoDTO;
import com.gimi.cloud.bbp.entity.userInfo.RdExpressInfoEntity;

/**
 * 用户配送信息管理
 * @author chendi
 * @date 2017年12月28日
 */
@RestController
@RequestMapping(value = "userExpress")
public class UserExpressController {

    @Autowired
    private RdExpressInfoService userExpressService;
    
    /**
     * 新添加user配送信息
     * @param userInfoDTO
     * @param response
     */
    @RequestMapping(value = "/add")
    public void addUserInfo(@RequestBody RdExpressInfoDTO rdExpressInfoDTO, HttpServletResponse response) {
        Response resp = new Response();
        userExpressService.addExpressInfo(rdExpressInfoDTO);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED,"添加成功");
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }   
    /** 
     * 根据e_id查询user配送信息
     */
    @RequestMapping(value = "/single")
    public void single(@RequestBody RdExpressInfoDTO rdExpressInfoDTO, HttpServletResponse response) {
        Response resp = new Response();
        RdExpressInfoEntity expressInfoEntity = userExpressService.getExpressInfoSingle(rdExpressInfoDTO);
        if (expressInfoEntity==null) {
			throw new MsgException(ResponseCodeEnum.NO_DATA);
		}
        resp.setRes_data(expressInfoEntity);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }
    /**
     * 更新配送信息
     * @param userInfoDTO
     * @param response
     */
    @RequestMapping(value = "/update")
    public void updateUserInfo(@RequestBody RdExpressInfoDTO rdExpressInfoDTO, HttpServletResponse response) {
        Response resp = new Response();
        userExpressService.updateExpressInfo(rdExpressInfoDTO);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }
    /**
     * 根据user_id查询配送信息列表
     */
    @RequestMapping(value = "/pageList")
    public void pageListByUser(@RequestBody RdExpressInfoDTO rdExpressInfoDTO, HttpServletResponse response) {
        Response resp = new Response();
        resp.setRes_data(userExpressService.expressListByUser(rdExpressInfoDTO));
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }
    
    @RequestMapping(value = "/expressDelete")
    public void expressDelete(@RequestBody RdExpressInfoDTO rdExpressInfoDTO, HttpServletResponse response) {
        Response resp = new Response();
        resp.setRes_data(userExpressService.expressDelete(rdExpressInfoDTO,false));
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }

}
